package com.ad2campaign.engine.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ad2campaign.engine.core.service.GenericJobService;
import com.ad2campaign.engine.rest.RestActionResponse;

@Controller
public class JobController 
{
 
 	@Autowired
	private GenericJobService genericJobService;

	@RequestMapping("/ping/")
	@ResponseBody public  RestActionResponse ping()
	{
		RestActionResponse response = new RestActionResponse();
	 	response.setStatus(true);
	 	return response;
	} 	
 	
 
 	
 	
	@RequestMapping("/{jobName}/start/")
	@ResponseBody public RestActionResponse startJob(@PathVariable("jobName") String jobName, @RequestParam("jobParam") String jobParam)
	{
		return genericJobService.startJob(jobName, jobParam);
	}
	
	@RequestMapping("/{jobName}/stop/{jobId}/")
	@ResponseBody public RestActionResponse stopJob(@PathVariable("jobId") Long executionId,@PathVariable("jobName") String jobName)
	{		
		 
		return genericJobService.stopJob(executionId, jobName) ;
 	}

  	
	
	@RequestMapping("/{jobName}/restart/{jobId}/")
	@ResponseBody public RestActionResponse restart(@PathVariable("jobName") String jobName,@PathVariable("jobId") Long executionId)
	{
		return genericJobService.restart(jobName, executionId);
	}
	
 
	@RequestMapping("/{jobName}/running/")
	@ResponseBody public RestActionResponse running(@PathVariable("jobName") String jobName)
	{
		return genericJobService.running(jobName);
 	}

  
	
	@RequestMapping("/{jobName}/stopped/")
	@ResponseBody public RestActionResponse stopped(@PathVariable("jobName") String jobName)
	{
		return genericJobService.stopped(jobName);
 	}
	
	@RequestMapping("/{jobName}/stopping/")
	@ResponseBody public RestActionResponse stopping(@PathVariable("jobName") String jobName)
	{
		return genericJobService.stopping(jobName);

 	}
	
	@RequestMapping("/{jobName}/starting/")
	@ResponseBody public RestActionResponse starting(@PathVariable("jobName") String jobName)
	{
		return genericJobService.starting(jobName);
 	}

 	@RequestMapping("/{jobName}/completed/")
	@ResponseBody public RestActionResponse completed(@PathVariable("jobName") String jobName)
	{
 		return genericJobService.completed(jobName);
 	}

	@RequestMapping("/{jobName}/failed/")
	@ResponseBody public RestActionResponse failed(@PathVariable("jobName") String jobName)
	{
		return genericJobService.failed(jobName);
 	}
 


	
	
  
	 	
}
